/**
 * 创建class文件类
 * @param {} params
 * @param {} config
 */
DC.front.win.CreateClassWin = function(params, config) {
	var creClassWin = this;
	var project_id = '',
		project_name = '',
		package_name = '';
	if (params) {
		project_id = params.project_id;
		project_name = params.project_name;
		package_name = params.package_name;
	}
	DC.front.win.CreateClassWin.superclass.constructor.call(this, Ext.apply({
    	id : 'new_class_win',
    	title : 'New Java Class',
        border : true,
        bodyBorder : true,
        modal : true,
        closeAction : 'close',
        frame : true,
        width : 430,
        height : 450,
        layout : 'column',
        bodyStyle : 'padding:10px 10px; background:#fff',
        defaults : {
        	border : false,
		    bodyBorder : false,
		    columnWidth : 1
        },
        items : [{
        	layout : 'form',
        	labelAlign : 'left',
        	labelWidth : 70,
        	defaults : {
                labelSeparator : '',
                style : 'margin-bottom:10px;',
                anchor : '100%'
            },
        	items : [{
        		xtype : 'textfield',
        		id : 'new_class_win_package_txt',
        		name : 'package',
        		fieldLabel : 'Package',
        		value : package_name,
	        	regex : /^[^\.][^\/\\<>\*\?\:"\|]*[^\/\\<>\*\?\:"\|\.]$/,
                regexText : 'Package is Illegal.',
                enableKeyEvents: true, // 只有将此属性设置成true，此控件的键盘事件才生效
                listeners : {
	        		keyup : function() {
	        			var created_btn = Ext.getCmp('new_class_win_created_btn');
	        			if (this.isValid() && Ext.getCmp('new_class_win_class_name_txt').isValid()) {
	        				created_btn.enable();
	        			} else {
	        				created_btn.disable();
	        			}
	        		}
	        	}
        	}, {
        		xtype : 'textfield',
        		id : 'new_class_win_class_name_txt',
        		name : 'name',
        		fieldLabel : 'Name',
	        	allowBlank : false,
	        	blankText : 'Class name cannot be empty.',
	        	regex : /^[^\/\\<>\*\?\:"\|\.]*[^\/\\<>\*\?\:"\|\.]$/,
                regexText : 'Class name is Illegal.',
                enableKeyEvents: true, // 只有将此属性设置成true，此控件的键盘事件才生效
                listeners : {
                	keyup : function() {
	        			var created_btn = Ext.getCmp('new_class_win_created_btn');
	        			if (this.isValid() && Ext.getCmp('new_class_win_package_txt').isValid()) {
	        				created_btn.enable();
	        			} else {
	        				created_btn.disable();
	        			}
	        		}
	        	}
        	}]
        }, {
    		layout : 'column',
    		defaults : {
				border : false,
    		    bodyBorder : false
			},
			style : 'margin-bottom:10px;',
    		items : [{
    			columnWidth : .8,
    			layout : 'form',
    			labelWidth : 70,
    			items : [{
    				xtype : 'textfield',
            		id : 'new_class_win_superclass_txt',
            		name : 'superclass',
            		fieldLabel : 'Superclass',
    	        	value : 'java.lang.Object',
    	        	anchor : '95%',
                    enableKeyEvents: true, // 只有将此属性设置成true，此控件的键盘事件才生效
                    listeners : {
    	        		keyup : function() {
    	        			
    	        		}
    	        	}
    			}]
    		}, {
    			columnWidth : .2,
    			xtype : 'button',
    			text : 'Browse...',
    			handler :function(){
    				
    			} 
    		}]
        }, {
    		layout : 'column',
    		defaults : {
				border : false,
    		    bodyBorder : false
			},
    		items : [{
    			layout : 'form',
    			columnWidth : .8,
    			anchor : '100%',
    			autoScroll : false,
    			style : 'margin-right:15px;',
    			labelWidth : 70,
    			height : 180,
    			items : [{
    				xtype : 'multiselect',
    				id : 'new_class_win_interface_multiselect',
    				anchor : '100% 90%',
    				width : 205,
    				height : 150,
    	            fieldLabel : 'Interface',
    	            name : 'interface',
    	            store : [],
    	            value : [],
    	            ddReorder : true
    			}]
    		}, {
    			layout : 'anchor',
    			columnWidth : .2,
    			items : [{
        			anchor : '100%',
        			xtype : 'button',
        			text : 'Browse...',
        			style : 'margin-bottom:10px;',
        			handler :function(){
        				
        			}
        		}, {
        			anchor : '100%',
        			xtype : 'button',
        			text : 'Remove...',
        			handler :function(){
        				
        			}
        		}]
    		}]
        }, {
    		xtype : 'fieldset',
    		title : '<span style="color:#000; font-weight:normal;">Which method stubs would you like to create?</span>',
    		autoHeight: true,
    		border : true,
		    bodyBorder : true,
		    bodyStyle : 'margin:5px 0px;',
    		defaultType : 'checkbox',
    		hideLabels : true,
    		Style : 'padding:5px 5px;',
    		defaults : {
    			style : 'margin-left:30px',
    		},
    		items : [{
    			xtype : 'checkboxgroup',
    			id : 'new_class_win_method_checkboxgroup',
    		    columns : 1,
    		    items : [{
	    			boxLabel : 'Constructors from superclass',
	    			name: 'constructor',
	    			value: 'constructor',
					width: 'auto'
		        }, {
	    			boxLabel : 'public static void main(String[] args)',
	    			name: 'main',
	    			value: 'main',
					width: 'auto'
    	    	}]
    		}]
    	}],
        buttons : [{
        	id : 'new_class_win_created_btn',
			text : 'Create',
			disabled : true,
			handler :function(){
				var package_val = Ext.getCmp('new_class_win_package_txt').getValue();
				var class_val = Ext.getCmp('new_class_win_class_name_txt').getValue();
				var superClass_val = Ext.getCmp('new_class_win_superclass_txt').getValue();
				var interface_val = Ext.getCmp('new_class_win_interface_multiselect').getValue();
				var checkboxs = Ext.getCmp('new_class_win_method_checkboxgroup').getValue();
				var method = '';
				for (var i = 0, len = checkboxs.length; i < len; i++) {
					method = method + checkboxs[i].getName() + ',';
				}
				method = method.substring(0, method.length - 1);
				creClassWin.create({
					'clazz.projectName' : project_name,
					'clazz.packageName' : package_val,
					'clazz.className' : class_val,
					'clazz.superClassPackage' : superClass_val,
					'clazz.implementPackage' : interface_val,
					'clazz.method' : method
				});
			} 
		}, {
			text : 'Cancle',
			handler :function(){
				creClassWin.close();
			} 
		}]
    }, config ||{}));
};

Ext.extend(DC.front.win.CreateClassWin, Ext.Window, {
	create : function(param) {
		var cw = this;
		var project_name = param['clazz.projectName'];
		var package_val = param['clazz.packageName'];
		var className = param['clazz.className'];
		var type = 'java';
		DC.util.CommonAction.loadMask("Creading...");
		Ext.Ajax.request({
		    url : DC.url.CREATE_CLASS,
		    method : 'POST',
		    params : param,
		    success : function(response, options){
		    	DC.util.CommonAction.unMask();
			    var res = Ext.util.JSON.decode(response.responseText);
			    if (res.success) {
			    	cw.close();
			    	DC.obj.explorer_treePanel.reloadData();
					var path = project_name + "/src/" + package_val.replace(/\./g, "/");
					var code_editor = new DC.front.CodeEditor({
						parentPath : path,
						fileName : className,
						fileType : type,
						code : res.content
					});
					
			    	DC.obj.editor_tabPanel.addTab({
			    		id : path.replace(/\//g, '_') + '_' + className + '_' + type,
			    		panel : code_editor
			    	});
			    } else {
			    	Ext.example.msg('Prompt', res.msg, res.type);
			    }
			    
		    },
		    failure : function(response, options){
		    	DC.util.CommonAction.unMask();
            	Ext.example.msg('Verification Win', response.responseText, 'error');
		    }
	    });
	}
});